<template>
  <view class="content">
    <view class="unit">
      <view class="title">律所信息</view>
      <view>
        <u-swiper :list="unitList" showTitle keyName="img" interval="1000" height="200" imgMode="aspectFit" @click="goUnit"></u-swiper>
      </view>
    </view>
    <view class="lawyer">
      <view class="title">律师信息</view>
      <view class="">
        <view
          v-for="item in lawyerProfileList"
          :key="item.userId"
          class="lawyer-item"
          @click="goUser(item)"
        >
          <image class="avatar" :src="getUrl(item.avatar)"></image>
          <view class="right">
            <view class="u-line-1 name">{{ item.nickName }}</view>
            <view class="u-line-2 profile">{{ item.personalProfile }}</view>
          </view>
        </view>
      </view>
    </view>
  </view>
</template>

<script>
import { mapGetters } from 'vuex'
import config from '../request/config'
import lawyerApi from '../request/api/lawyer'

export default {
  data() {
    return {
      unitList: [],
      lawyerProfileList: []
    }
  },
  onLoad() {
    this.getUnit()
    this.getLawyer()
  },
  computed: {
    ...mapGetters('userInfo', ['user', 'isGridWorker', 'isCommon', 'isMerchant', 'isLawyer', 'isNightMarketAdministrator']),
  },
  methods: {
    goInfo(item) {
      uni.navigateTo({
        url: item.url
      });
    },
    // 获取律师列表
    async getLawyer() {
      const { rows } = await lawyerApi.getLawyerProfileList({
        pageNum: 1,
        pageSize: 10,
      })
      this.lawyerProfileList = rows
    },
    // 获取律所列表
    async getUnit() {
      const { data } = await lawyerApi.getDeptList({
        pageNum: 1,
        pageSize: 10,
      })
      this.unitList = data.map(i => ({
        img: this.handleUrl(i.firmImages),
        title: i.deptName,
        deptId: i.deptId
      }))
    },
    handleUrl(images) {
      return images?.split?.(",")?.[0] ? config.baseUrl + images.split(",")[0] : ''
    },
    getUrl(image) {
      return image ? config.baseUrl + image : 'https://sanshengcai.com/home/images/logo.png'
    },
    /**
     * 跳转律所详情
     * @param {*} index 索引
     */
    goUnit(index) {
      uni.navigateTo({
        url: `/lawyer/unitDetail?deptId=${ this.unitList[index].deptId }`
      })
    },
    // 跳转律师详情页
    goUser(item) {
      uni.navigateTo({
        url: `/lawyer/profile?lawyerId=${ item.id }`
      })
    }
  },
  onShareAppMessage() {
    return {
      title: '法律援助',
      path: `/lawyer/rescue`, // 分享路径
    }
  }
}
</script>

<style>
page {
  background-color: #F8F8F8;
}
</style>

<style scoped lang="scss">
.unit {
  margin: 40rpx;
  padding: 20rpx;
  border-radius: 10rpx;
  background-color: #fff;
}
.lawyer {
  margin: 40rpx;
  padding: 20rpx;
  border-radius: 10rpx;
  background-color: #fff;
}

.title {
  font-size: 34rpx;
  margin-bottom: 10rpx;
  &::before {
    content: '';
    display: inline-block;
    position: relative;
    top: 10rpx;
    width: 8rpx;
    height: 40rpx;
    background: #4080FF;
    border-radius: 999px;
    margin-right: 10rpx;
  }
}

.lawyer-item {
  display: flex;
  align-items: center;
  margin: 30rpx 0;
  .avatar {
    flex-shrink: 0;
    width: 130rpx;
    height: 130rpx;
    border-radius: 10rpx;
  }
  .right {
    margin-left: 20rpx;
  }
  .name {
    font-size: 32rpx;
    margin-bottom: 10rpx;
  }
  .profile {
    font-size: 28rpx;
    color: #999999;
  }
}
</style>
